package com.ruoyi.web.controller.chargeback.controller;


import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.charge.vo.RecordVo;
import com.ruoyi.charge.bo.RecordQueryBo;
import com.ruoyi.charge.bo.RecordAddBo;
import com.ruoyi.charge.bo.RecordEditBo;
import com.ruoyi.charge.service.IRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 充电记录Controller
 *
 * @author fanqie
 * @date 2021-10-28
 */
@Api(value = "充电记录控制器", tags = {"后台充电记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/back/record")
public class BackRecordController extends BaseController {

    private final IRecordService iRecordService;

    /**
     * 查询充电记录列表
     */
    @ApiOperation("查询充电记录列表")
    @PreAuthorize("@ss.hasPermi('back:record:list')")
    @GetMapping("/list")
    public TableDataInfo<RecordVo> list(RecordQueryBo bo) {
        startPage();
        List<RecordVo> list = iRecordService.queryList2(bo);
        return getDataTable(list);
    }

    /**
     * 导出充电记录列表
     */
    @ApiOperation("导出充电记录列表")
    @PreAuthorize("@ss.hasPermi('back:record:export')")
    @Log(title = "充电记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<RecordVo> export(RecordQueryBo bo) {
        List<RecordVo> list = iRecordService.queryList(bo);
        ExcelUtil<RecordVo> util = new ExcelUtil<RecordVo>(RecordVo.class);
        return util.exportExcel(list, "充电记录");
    }

    /**
     * 获取充电记录详细信息
     */
    @ApiOperation("获取充电记录详细信息")
    @PreAuthorize("@ss.hasPermi('back:record:query')")
    @GetMapping("/{id}")
    public AjaxResult<RecordVo> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iRecordService.queryById(id));
    }

    /**
     * 新增充电记录
     */
    @ApiOperation("新增充电记录")
    @PreAuthorize("@ss.hasPermi('back:record:add')")
    @Log(title = "充电记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody RecordAddBo bo) {
        return toAjax(iRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改充电记录
     */
    @ApiOperation("修改充电记录")
    @PreAuthorize("@ss.hasPermi('back:record:edit')")
    @Log(title = "充电记录", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody RecordEditBo bo) {
        return toAjax(iRecordService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除充电记录
     */
    @ApiOperation("删除充电记录")
    @PreAuthorize("@ss.hasPermi('back:record:remove')")
    @Log(title = "充电记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
